package com.neusoft.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.po.CommonResult;
import com.neusoft.po.Review;
import com.neusoft.service.ReviewService;

@RestController
@RequestMapping("/Review")
@RefreshScope // 开启动态刷新
public class ReviewController {

	@Autowired
	private ReviewService reviewService;

	@GetMapping("/ReviewListOfFood")
	public CommonResult<List> listReviewByFoodId(Review review) {
		return new CommonResult<List>(200, "success", reviewService.listReviewByFoodId(review.getFoodId()));
	}

	@GetMapping("/ReviewListOfUser")
	public CommonResult<List> listReviewByUserId(Review review) {
		return new CommonResult<List>(200, "success", reviewService.listReviewByUserId(review.getUserId()));
	}

	// save
	@PostMapping("/ReviewId")
	public CommonResult<Integer> saveReview(Review review) {
		return new CommonResult<Integer>(200, "success", reviewService.saveReview(review));
	}

	// remove
	@DeleteMapping("/ReviewId")
	public CommonResult<Integer> removeReview(Review review) {
		return new CommonResult<Integer>(200, "success", reviewService.removeReview(review.getReviewId()));
	}

}